{include file="header.tpl"}

   <h1>Tickets</h1>

   <div id="content">
   
      {include file="flashes.tpl"}
      
      <div class="action_bar">
         <a class="add" href="{$spf.base_url}/tickets/edit">Add a ticket</a>
         <a class="export" href="{$spf.base_url}/tickets/export">Export to CSV</a>
      </div>
      
      <form id="frm_ticket_filter" class="filter" action="" method="get">
   
         <div class="hidden">
            <input type="hidden" id="url" name="url" value="tickets/browse/{$project_id}" />
            <input type="hidden" id="order_by" name="order_by" value="{$filter.order_by}{$filter.order_dir}" />
            <input type="hidden" id="page_no" name="page" value="1" />
         </div>
         
      	<fieldset class="panel">
      		
      		<div id="basic">
            	<div>
            		<label for="ticket_id">ID:</label>
            		<input id="ticket_id" name="ticket_id" type="text" value="{$filter.conditions.ticket_id.value}" />
            	</div>
               
            	<div>
            		<label for="title">Title:</label>
            		<input id="title" name="title" type="text" value="{$filter.conditions.title.value}" />
            	</div>
               
      			<div>
      				<label for="ticket_type">Type:</label>
           			<select id="ticket_type" name="ticket_type">
                     <option value="">-- Any --</option>
                     {foreach key=id item=description from=$filter.conditions.ticket_type.options}
                     <option value="{$id}"{if $filter.conditions.ticket_type.value == $id}{$spf.selected}{/if}>{$description}</option>
                     {/foreach}
                  </select>
      	 		</div>
      			
      			<div>
      				<label for="ticket_status">Status:</label>
           			<select id="ticket_status" name="ticket_status">
                     <option value="">-- Any --</option>
                     {foreach key=id item=description from=$filter.conditions.ticket_status.options}
                     <option value="{$id}"{if $filter.conditions.ticket_status.value == $id}{$spf.selected}{/if}>{$description}</option>
                     {/foreach}
                  </select>
      	 		</div>
      			
      			<div>
      				<label for="assigned_user">Assigned To:</label>
           			<select id="assigned_user" name="assigned_user">
                     <option value="">-- Anyone --</option>
                     {foreach key=user_name item=display_name from=$filter.conditions.assigned_user.options}
                     <option value="{$user_name}"{if $filter.conditions.assigned_user.value == $user_name}{$spf.selected}{/if}>{$display_name}</option>
                     {/foreach}
                  </select>
      	 		</div>
      	 	</div>
      	 	
      	 	<div id="advanced" class="{if !$filter.conditions.component.value
                                       && !$filter.conditions.milestone.value
                                       && !$filter.conditions.ticket_priority.value
                                       && !$filter.conditions.ticket_severity.value
                                       && ($filter.conditions.include_closed.value == $filter.conditions.include_closed.default) }hidden{/if}">
         	 	
      			<div>
      				<label for="component">Component:</label>
           			<select id="component" name="component">
                     <option value="">-- Any --</option>
                     {foreach key=id item=description from=$filter.conditions.component.options}
                     <option value="{$id}"{if $filter.conditions.component.value == $id}{$spf.selected}{/if}>{$description}</option>
                     {/foreach}
                  </select>
      	 		</div>
      			
      			<div>
      				<label for="milestone">Milestone:</label>
           			<select id="milestone" name="milestone">
                     <option value="">-- Any --</option>
                     {foreach key=id item=description from=$filter.conditions.milestone.options}
                     <option value="{$id}"{if $filter.conditions.milestone.value == $id}{$spf.selected}{/if}>{$description}</option>
                     {/foreach}
                  </select>
      	 		</div>
      			
      			<div>
      				<label for="ticket_priority">Priority:</label>
           			<select id="ticket_priority" name="ticket_priority">
                     <option value="">-- Any --</option>
                     {foreach key=id item=description from=$filter.conditions.ticket_priority.options}
                     <option value="{$id}"{if $filter.conditions.ticket_priority.value == $id}{$spf.selected}{/if}>{$description}</option>
                     {/foreach}
                  </select>
      	 		</div>
      			
      			<div>
      				<label for="ticket_severity">Severity:</label>
           			<select id="ticket_severity" name="ticket_severity">
                     <option value="">-- Any --</option>
                     {foreach key=id item=description from=$filter.conditions.ticket_severity.options}
                     <option value="{$id}"{if $filter.conditions.ticket_severity.value == $id}{$spf.selected}{/if}>{$description}</option>
                     {/foreach}
                  </select>
      	 		</div>
      			
            	<div class="checkbox">
                  <input type="checkbox" id="include_closed" name="include_closed" value="1"{if $filter.conditions.include_closed.value != $filter.conditions.include_closed.default}{$spf.checked}{/if} />
                  <label for="include_closed" class="option">Include closed tickets</label>
              	</div>
              	
      	 	</div>
      	 	
            <div class="button_bar">
         		<button type="submit" name="submit_frm_ticket_filter" value="1">Search</button>
         		<a id="toggle_advanced_filter" href="javascript:spf.sitrack.toggle_advanced_filter()">{if !$filter.conditions.component.value
                     && !$filter.conditions.milestone.value
                     && !$filter.conditions.ticket_priority.value
                     && !$filter.conditions.ticket_severity.value
                     && ($filter.conditions.include_closed.value == $filter.conditions.include_closed.default) }More options{else}Less options{/if}...</a>
         	</div>
         	
      	</fieldset>
      
      </form>
      
      <table class="max_width">
         <thead>
            {if $tickets.page_count > 0}
            <tr class="datanav">
            	<th colspan="10">
                  <span class="datanav">
            			{$tickets.links}
            		</span>
            		{if $tickets.current_page == -1}
            		{$tickets.record_count} Records
            		{else}
            		Page {$tickets.current_page} of {$tickets.page_count} &nbsp;({$tickets.record_count} Records)
            		{/if}
            	</th>
            </tr>
            {/if}
            <tr class="headers">
               <th class="center"><a href="{$base_url}&amp;order_by=id{if $filter.order_by == 'id'}{$filter.toggle_order_dir}{else}Desc{/if}">ID</a></th>
               <th><a href="{$base_url}&amp;order_by=type{if $filter.order_by == 'type'}{$filter.toggle_order_dir}{else}Asc{/if}">Type</a></th>
               <th><a href="{$base_url}&amp;order_by=title{if $filter.order_by == 'title'}{$filter.toggle_order_dir}{else}Asc{/if}">Title</a></th>
               <th><a href="{$base_url}&amp;order_by=assigned{if $filter.order_by == 'assigned'}{$filter.toggle_order_dir}{else}Asc{/if}">Assigned To</a></th>
               <th><a href="{$base_url}&amp;order_by=status{if $filter.order_by == 'status'}{$filter.toggle_order_dir}{else}Asc{/if}">Status</a></th>
               <th><a href="{$base_url}&amp;order_by=created{if $filter.order_by == 'created'}{$filter.toggle_order_dir}{else}Desc{/if}">Created</a></th>
               <th><a href="{$base_url}&amp;order_by=updated{if $filter.order_by == 'updated'}{$filter.toggle_order_dir}{else}Desc{/if}">Updated</a></th>
               <th class="center">View</th>
            </tr>
         </thead>
         <tbody>
            {foreach item=ticket from=$tickets.data}
            <tr class="{cycle values=",alt"}">
               <td class="center">{$ticket.id}</td>
               <td class="nowrap">{$ticket.type_desc}</td>
               <td>{$ticket.title}</td>
               <td class="nowrap">{$ticket.assigned_to}</td>
               <td class="nowrap">{$ticket.status_desc}</td>
               <td class="nowrap">{$ticket.created_date}<br />{$ticket.created_by}</td>
               <td class="nowrap">{$ticket.updated_date}<br />{$ticket.updated_by}</td>
               <td class="view"><a href="{$spf.base_url}/tickets/view/{$ticket.id}"></a></td>
            </tr>
            {/foreach}
            {if !$tickets.data}<tr><td class="norecords" colspan="10">No records found.</td></tr>{/if}
         </tbody>
      </table>

      <div class="clear"></div>
      
   </div>
   
{include file="footer.tpl"}
